package com.ns002.yigou.quote.common.config;

import com.google.gson.Gson;
import com.ns002.yigou.quote.common.api.EBuyQuoteAPI;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @Author xu
 * @Date 2017/7/26 0026 下午 9:28
 * 易购网络配置
 */
@Configuration
public class EbuyNetworkConfig {

    @Value("${ebuy.server}")
    private String EBUY_SERVER;

    /**
     * 易购行情服务器
     *
     * @param gson
     * @param okHttpClient
     * @return
     */
    @Bean("ebuyQuoteAPI")
    public EBuyQuoteAPI ebuyQuoteAPI(@Autowired Gson gson, @Autowired OkHttpClient okHttpClient) {
        //构建Retrofit
        Retrofit retrofit = new Retrofit.Builder()
                //配置服务器路径
                .baseUrl(EBUY_SERVER)
                //配置转化库，默认是Gson
                .addConverterFactory(GsonConverterFactory.create(gson))
                //配置回调库，采用RxJava
//                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                //设置OKHttpClient为网络客户端
                .client(okHttpClient)
                .build();

        return retrofit.create(EBuyQuoteAPI.class);
    }

}
